const labelService = require("../service/label.service");

class LabelController {
  async create(ctx, next) {
    try {
      const { name } = ctx.request.body;

      const result = await labelService.create(name);

      ctx.body = {
        code: 0,
        message: "新增标签成功~",
        data: result,
      };
    } catch (error) {
      console.log("新增标签", error);
    }
  }

  // 查询标签列表
  async list(ctx, next) {
    try {
      const { offset, size } = ctx.query;
      const result = await labelService.list(offset, size);
      ctx.body = {
        code: 0,
        message: "查询标签成功~",
        data: result,
        total: result.length,
      };
    } catch (error) {
      console.log(error);
    }
  }
}

module.exports = new LabelController();
